package com.wjr;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author: wjr
 * @Description: Jedis连接redis集群Demo
 * @Date Created in  2020-10-04 6:15
 * @Modified By:
 */
public class Demo2 {
    public static void main(String[] args) throws IOException {
        //1.创建一个集合，保存集群信息
        Set set = new HashSet<>();
        set.add(new HostAndPort("192.168.168.101",7001));
        set.add(new HostAndPort("192.168.168.101",7002));
        set.add(new HostAndPort("192.168.168.101",7003));
        set.add(new HostAndPort("192.168.168.101",7004));
        set.add(new HostAndPort("192.168.168.101",7005));
        set.add(new HostAndPort("192.168.168.101",7006));

        //2.创建集群操作对象
        JedisCluster jedisCluster = new JedisCluster(set);

        //3.操作数据
        jedisCluster.set("demo","demo_value");
        String s = jedisCluster.get("demo");
        System.out.println(s);

        //4.关闭资源
        jedisCluster.close();
    }
}
